//
//  ArtConfirmViewController.m
//  EasyToo
//
//  Created by Jr Lan on 13-9-2.
//
//

#import "ArtConfirmViewController.h"
#import "NetworkAlertView.h"
#import <QuartzCore/QuartzCore.h>

@interface ArtConfirmViewController ()

@end

@implementation ArtConfirmViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    //加载视图
    [self init_view];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//加载视图
- (void)init_view
{
    self.title = @"演艺票";
    //加载背影
    [self.view setBackgroundColor:BackgroundColor];
    
    int width = [DeviceUtil getScreenWidth];
    int heigth = self.view.frame.size.height;
    
    UIScrollView *myscrollview = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, width, heigth)]autorelease];
    myscrollview.directionalLockEnabled = YES; //只能一个方向滑动
    myscrollview.pagingEnabled = NO; //是否翻页
    myscrollview.backgroundColor = [UIColor whiteColor];
    myscrollview.showsVerticalScrollIndicator =YES; //垂直方向的滚动指示
    myscrollview.indicatorStyle = UIScrollViewIndicatorStyleWhite;//滚动指示的风格
    myscrollview.showsHorizontalScrollIndicator = NO;//水平方向的滚动指示
    myscrollview.delegate = self;
    CGSize newSize = CGSizeMake(width, 500);
    [myscrollview setContentSize:newSize];
    
    //加载图片
    UIImageView *imgView = [[[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 280, 330)]autorelease];
    imgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    imgView.image = [UIImage imageNamed:@"表格8行.png"];
    [myscrollview addSubview:imgView];
    
    NSMutableArray *textarray = [[NSMutableArray alloc]init];
    [textarray addObject:[NSString stringWithFormat:@"演出：%@", self.artInfo.ProjectName]];
    [textarray addObject:[NSString stringWithFormat:@"日期：%@", self.artInfo.PerformTime]];
    [textarray addObject:[NSString stringWithFormat:@"数量：%@张", self.count]];
    [textarray addObject:[NSString stringWithFormat:@"单价：%@", self.cash]];
    int deliverfee = [self.SumPrice intValue] - ([self.count intValue] * [self.cash intValue]);
    [textarray addObject:[NSString stringWithFormat:@"快递费：%d元", deliverfee]];
    [textarray addObject:[NSString stringWithFormat:@"地址：%@", self.address]];
    if (self.type == 1) {
        [textarray addObject:@"支付方式：网银支付"];
    } else {
        [textarray addObject:@"支付方式：支付宝支付"];
    }

    [textarray addObject:[NSString stringWithFormat:@"                                 合计：%@元", self.SumPrice]];

    int i;
    for (i = 0; i < [textarray count]; i ++) {
        UILabel *textlbl = [[[UILabel alloc]initWithFrame:CGRectMake(50, 70+32*i, 280, 30)]autorelease];
        textlbl.text = [textarray objectAtIndex:i];
        textlbl.font = [UIFont systemFontOfSize:15];
        textlbl.backgroundColor = [UIColor clearColor];
        textlbl.adjustsFontSizeToFitWidth = YES;
        [myscrollview addSubview:textlbl];
    }
    [textarray release];
    
    UIButton *nextStep =[UIButton buttonWithType:UIButtonTypeCustom];
    nextStep.frame = CGRectMake(40, 350, 230, 40);
    [nextStep setBackgroundImage:[UIImage imageNamed:@"xyb"] forState:UIControlStateNormal];
    [nextStep setTitle:@"下一步" forState:UIControlStateNormal];
    nextStep.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    nextStep.layer.borderColor = [UIColor grayColor].CGColor;
    nextStep.layer.borderWidth = 1 ;
    nextStep.layer.cornerRadius = 10 ;
    [myscrollview addSubview:nextStep];
    [nextStep addTarget:self action:@selector(confirmMessge) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:myscrollview];
    
}

- (void)confirmMessge
{
    ArtManager *artmanager = [ArtManager shareManager];
    artmanager.delegate = self;
    [[NetworkAlertView shareView] showNetView];
    [artmanager confirmBuyArtTicket:self.OrderId
                             amount:self.amount
                        projectName:self.address
                              phone:self.phone
                           allPrice:[self.SumPrice intValue]];
}


//购买门票
- (void)confirmArtInfo:(BOOL)isSuccess tn:(NSString*)tn
{
    [[NetworkAlertView shareView] delView];
    if (isSuccess) {
        [UPPayPlugin startPay:tn sysProvide:nil spId:nil mode:PAY_MODE_REALEASE viewController:self delegate:self];
    } else {
        UIAlertView* baseAlert = [[[UIAlertView alloc] initWithTitle:@"下单失败" message:nil delegate:self cancelButtonTitle:@"下单失败，请重新尝试，谢谢" otherButtonTitles: nil] autorelease];
        [baseAlert show];
    }
}

-(void)UPPayPluginResult:(NSString*)result
{
    NSString *alertString = nil;
    if ([result isEqualToString:@"success"])
    {
        alertString = @"交易成功";
    }
    else if ([result isEqualToString:@"cancel"])
    {
        alertString = @"交易取消";
    }
    else
    {
        alertString = @"交易失败";
    }
    
    UIAlertView *alert = [[UIAlertView alloc]  initWithTitle:@"支付结果" message:alertString  delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
    [alert show];
}

@end

